﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ChallengePuzzle.Lib;
using System.Diagnostics;
namespace ChallengePuzzle
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int X = int.Parse(textBox1.Text);
            int Y = int.Parse(textBox2.Text);

            Lucky lucky = new Lucky();

            TimeChecker.Start();

            LuckyNumbers luckyNumbers= lucky.SearchLuckyNumbers(X,Y);

            DisplayNumbers(luckyNumbers,TimeChecker.StopMilliseconds());
        }

        private void DisplayNumbers(LuckyNumbers luckyNumbers,long timeConsume)
        {
            textBox3.Text = "计算完成!" + "\r\n"
                            + "数量 : " + luckyNumbers.GetCount().ToString() + "\r\n" + "\r\n"
                            + "耗时 : " + timeConsume.ToString()
                           ;
            
            // luckyNumbers.ToMultiLines();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int X = int.Parse(textBox1.Text);
            int Y = int.Parse(textBox2.Text);
            
            ResultStr = "";

            if (radioButton1.Checked)
            {
                Plus(X,Y);
                return;
            }
            if (radioButton2.Checked)
            {
                Square(X, Y);
                return;
            }

        }

        string ResultStr = "";

        private  void Plus(int X, int Y)
        {
            

            IPlusSum PlusSum = PlusSumFactory.Create(comboBox1.Text);
            
            TimeChecker.Start();
            
            for (int i = X; i <= Y; i++)
            {
                int sum = PlusSum.GetPlusSum(i);

                //ResultStr +=i.ToString()+"的和\t=\t"+ sum.ToString()+"\r\n";
            }
           
            TimeChecker.StopAndShow();
        }

        private void Square(int X, int Y)
        {
            
            SquareSum SquareSum = new SquareSum();
            
            TimeChecker.Start();

            for (int i = X; i <= Y; i++)
            {

                ResultStr +=i.ToString()+"的平方和\t=\t"+ SquareSum.GetSquareSum(i).ToString() + "\r\n";

            }

            TimeChecker.StopAndShow();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox3.Text = ResultStr;
        }



    }
}
